<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">deferred.done()</h1>
<div class="entry-meta">
						所属分类：<span class="category"><a href="/category/deferred-object/">延迟对象</a></span>
<span class="pull-right">英文文档：<a href="https://api.jquery123.com/deferred.done/" target="_blank">deferred.done()</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<!-- .entry-header -->
<div class="entry-content">
<article class="entry method" id="deferred-done1"><h2 class="section-title">
<span class="name">deferred.done( doneCallbacks [, doneCallbacks ] )</span><span class="returns">返回: <a href="/Types/#Deferred">Deferred</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述: </strong> 当Deferred（延迟）对象解决时，调用添加处理程序。</p>
<ul class="signatures"><li class="signature" id="deferred-done-doneCallbacks-doneCallbacks">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.5/">1.5</a></span>deferred.done( doneCallbacks [, doneCallbacks ] )</h4>
<ul>
<li>
<div><strong>doneCallbacks</strong></div>
<div>类型: <a href="/Types/#Function">Function</a>()</div>
<div>
			        一个函数，或者函数数组，当Deferred（延迟）对象得到解决时被调用。
			      </div>
</li>
<li>
<div><strong>doneCallbacks</strong></div>
<div>类型: <a href="/Types/#Function">Function</a>()</div>
<div>
			        可选的一个函数，或者函数数组，当Deferred（延迟）对象得到解决时被调用。
			      </div>
</li></ul></li></ul></div>
<div class="longdesc" id="entry-longdesc">
<p><code>deferred.done()</code>方法接受一个或多个参数，所有这些都参数可以是一个单一的函数或一个函数数组。当Deferred（延迟）解决时，doneCallbacks被调用。回调是依照他们添加的顺序执行。一旦<code>deferred.done()</code>返回Deferred（延迟）对象，Deferred（延迟）可以链接其它的延迟对象，包括增加额外的<code>.done()</code>方法。当Deferred（延迟）解决，doneCallbacks执行，并且使用提供给<code><a href="/deferred.resolve">resolve</a></code>或<a href="/deferred.resolveWith"><code>resolveWith</code></a>方法的参数，依照被添加的顺序调用。有关详细信息，请参阅文件<a href="/category/deferred-object/">Deferred（延迟） 对象</a> 。</p></div>
<section class="entry-examples" id="entry-examples"><header><h2 class="underline">例子:</h2></header><div class="entry-example" id="example-0">
<h4>Example: <span class="desc">
			
			一旦<a href="/jQuery.get"><code>jQuery.get</code></a> 方法返回一个来自延迟的对象的jqXHR对象，我们可以附加一个成功回调使用<code>.done()</code> 方法。
			
			</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>$.get(<span class="string">"test.php"</span>).done(<span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code>  alert(<span class="string">"$.get succeeded"</span>);</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="entry-example" id="example-1">
<h4>Example: <span class="desc">当用户点击按钮时，受理延迟对象，触发一系列回调函数：</span>
</h4>
<div class="syntaxhighlighter xml ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
<div class="line n10">10</div>
<div class="line n11">11</div>
<div class="line n12">12</div>
<div class="line n13">13</div>
<div class="line n14">14</div>
<div class="line n15">15</div>
<div class="line n16">16</div>
<div class="line n17">17</div>
<div class="line n18">18</div>
<div class="line n19">19</div>
<div class="line n20">20</div>
<div class="line n21">21</div>
<div class="line n22">22</div>
<div class="line n23">23</div>
<div class="line n24">24</div>
<div class="line n25">25</div>
<div class="line n26">26</div>
<div class="line n27">27</div>
<div class="line n28">28</div>
<div class="line n29">29</div>
<div class="line n30">30</div>
<div class="line n31">31</div>
<div class="line n32">32</div>
<div class="line n33">33</div>
<div class="line n34">34</div>
<div class="line n35">35</div>
<div class="line n36">36</div>
<div class="line n37">37</div>
<div class="line n38">38</div>
<div class="line n39">39</div>
<div class="line n40">40</div>
<div class="line n41">41</div>
<div class="line n42">42</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="doctype">&lt;!DOCTYPE html&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">html</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">script</span> <span class="attribute">src</span>=<span class="value">"https://code.jquery.com/jquery-latest.js"</span>&gt;</span><span class="javascript"></span><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code> <span class="tag">&lt;<span class="title">button</span>&gt;</span>Go<span class="tag">&lt;/<span class="title">button</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> <span class="tag">&lt;<span class="title">p</span>&gt;</span>Ready...<span class="tag">&lt;/<span class="title">p</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">script</span>&gt;</span><span class="javascript"></span></code></div></div><div class="container"><div class="line"><code><span class="comment">/* 3 functions to call when the Deferred object is resolved */</span></code></div></div><div class="container"><div class="line"><code><span class="function"><span class="keyword">function</span> <span class="title">fn1</span><span class="params">()</span> {</span></code></div></div><div class="container"><div class="line"><code>  $(<span class="string">"p"</span>).append(<span class="string">" 1 "</span>);</code></div></div><div class="container"><div class="line"><code>}</code></div></div><div class="container"><div class="line"><code><span class="function"><span class="keyword">function</span> <span class="title">fn2</span><span class="params">()</span> {</span></code></div></div><div class="container"><div class="line"><code>  $(<span class="string">"p"</span>).append(<span class="string">" 2 "</span>);</code></div></div><div class="container"><div class="line"><code>}</code></div></div><div class="container"><div class="line"><code><span class="function"><span class="keyword">function</span> <span class="title">fn3</span><span class="params">(n)</span> {</span></code></div></div><div class="container"><div class="line"><code>  $(<span class="string">"p"</span>).append(n + <span class="string">" 3 "</span> + n);</code></div></div><div class="container"><div class="line"><code>}</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="comment">/* create a deferred object */</span></code></div></div><div class="container"><div class="line"><code><span class="keyword">var</span> dfd = $.Deferred();</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="comment">/* add handlers to be called when dfd is resolved */</span></code></div></div><div class="container"><div class="line"><code>dfd</code></div></div><div class="container"><div class="line"><code><span class="comment">/* .done() can take any number of functions or arrays of functions */</span></code></div></div><div class="container"><div class="line"><code>.done( [fn1, fn2], fn3, [fn2, fn1] )</code></div></div><div class="container"><div class="line"><code><span class="comment">/* we can chain done methods, too */</span></code></div></div><div class="container"><div class="line"><code>.done(<span class="keyword">function</span>(n) {</code></div></div><div class="container"><div class="line"><code>  $(<span class="string">"p"</span>).append(n + <span class="string">" we're done."</span>);</code></div></div><div class="container"><div class="line"><code>});</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="comment">/* resolve the Deferred object when the button is clicked */</span></code></div></div><div class="container"><div class="line"><code>$(<span class="string">"button"</span>).bind(<span class="string">"click"</span>, <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code>  dfd.resolve(<span class="string">"and"</span>);</code></div></div><div class="container"><div class="line"><code>});</code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">html</span>&gt;</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>Demo:</h4>
<div class="demo code-demo"></div>
</div></section>
</article></div></article>